package org.lai.controller;

import lombok.extern.slf4j.Slf4j;
import org.lai.pojo.Emp;
import org.lai.pojo.LoginInfo;
import org.lai.pojo.Result;
import org.lai.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class LoginController {
    @Autowired
    private EmpService empService; // 登录业务在EmpService中实现

    /**
     * 登录功能
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody Emp emp){
        log.info("登录:{}",emp);
        LoginInfo result = empService.login(emp);
        if(result != null){
            return Result.success(result);
        }
        return Result.error("用户名或密码错误~");

    }
}
